# Contributor: Leonardo Arena <rnalrd@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=drbd-utils
pkgver=9.27.0
pkgrel=0
pkgdesc="Network-based RAID 1"
url="https://www.drbd.org"
arch="all"
license="GPL-2.0-or-later"
depends="bash"
makedepends="
	asciidoctor
	bison
	docbook-xsl
	flex
	keyutils-dev
	libxslt
	linux-headers
	po4a
	"
options="!check"  # no tests provided
provides="drbd=$pkgver-r$pkgrel"
subpackages="
	$pkgname-bash-completion
	$pkgname-doc
	$pkgname-openrc
	$pkgname-pacemaker::noarch
	"
source="https://pkg.linbit.com/downloads/drbd/utils/drbd-utils-$pkgver.tar.gz
	drbdsetup-permissions.patch
	drbd.initd
	"

build() {
	CFLAGS="$CFLAGS -flto=auto" \
	CXXFLAGS="$CXXFLAGS -flto=auto" \
	./configure \
		--host=$CHOST \
		--build=$CBUILD \
		--disable-dependency-tracking \
		--prefix=/usr \
		--sbindir=/sbin \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--localstatedir=/var \
		--with-pacemaker \
		--with-drbdmon \
		--with-bashcompletion \
		--without-udev \
		--without-heartbeat \
		--without-rgmanager \
		--without-xen \
		--without-83support
	make
}

package() {
	make DESTDIR="$pkgdir" install

	install -m755 -D "$srcdir/drbd.initd" "$pkgdir/etc/init.d/drbd"

	mkdir -p "$pkgdir"/usr/share/bash-completion
	mv "$pkgdir"/etc/bash_completion.d \
		"$pkgdir"/usr/share/bash-completion/completions
}

pacemaker() {
	depends="$pkgname=$pkgver-r$pkgrel"

	amove usr/lib/ocf
}

sha512sums="
066849e77bac04515682f497398e3840eecdf16c866a0d67df4e8978e9278dee120d9a216ba7dcf16e1dc2cfdd7271ff775e5bee9ccd0cead8360b7e33e08f5d  drbd-utils-9.27.0.tar.gz
39a64a59577a28f8dc5f968bcfd35ab04b010ec1b9390dcaedefa609b8999ec4aabf2cfaf2db7dfd8348d8d09aca5720839de51b3bfb093960b3c61f92ebe4f0  drbdsetup-permissions.patch
f61a833dc5eea79000a7dd85e83ae10e284109c76b5d59974ed69f92dbab6c389d6d20f7ea374b7c066519c6d1d816ed27b48dbaee6b91fb9754974acf52f46e  drbd.initd
"
